Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for content_available for apns async #761

Merged
merged 4 commits into from
Feb 18, 2025

Conversation

pomali
Copy link
Contributor

@pomali pomali commented Feb 13, 2025

  • add content_available argument for async version of apns. Argument is sent as content-available to apns
  • add tests for content_available
  • format apns_async.py

(similar to #760)

pomali and others added 2 commits February 13, 2025 16:41
- add `content_available` argument for async version of apns. Argument is sent as `content-available` to apns
- add tests for `content_available`
- format `apns_async.py`
@pomali pomali requested a review from Copilot February 13, 2025 15:43

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.58%. Comparing base (44977b1) to head (63885f7).
Report is 55 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #761      +/-   ##
==========================================
+ Coverage   70.39%   72.58%   +2.19%     
==========================================
  Files          27       29       +2     
  Lines        1101     1244     +143     
  Branches      180      207      +27     
==========================================
+ Hits          775      903     +128     
- Misses        288      298      +10     
- Partials       38       43       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HashimJVZ HashimJVZ requested a review from 50-Course February 16, 2025 05:19
@HashimJVZ
Copy link
Contributor

@pomali This have some conflicts due to recent merge. Can you resolve?

@pomali
Copy link
Contributor Author

pomali commented Feb 17, 2025

@HashimJVZ I resolved the conflicts

@HashimJVZ
Copy link
Contributor

Do we need to add support for both bool and int?

Copy link
Member

@50-Course 50-Course left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @pomali, this looks great! can we stick to supporting bool only. its an effective and concise step forward.

...
content_type: bool = None
...

@pomali
Copy link
Contributor Author

pomali commented Feb 17, 2025

@HashimJVZ
Copy link
Contributor

Same goes for mutable-content.
This was the original code https://github.com/Pr0Ger/PyAPNs2/blob/master/apns2/payload.py

def dict(self) -> Dict[str, Any]:
        result = {
            'aps': {}
        }  # type: Dict[str, Any]

        if self.alert is not None:
            if isinstance(self.alert, PayloadAlert):
                result['aps']['alert'] = self.alert.dict()
            else:
                result['aps']['alert'] = self.alert
        if self.badge is not None:
            result['aps']['badge'] = self.badge
        if self.sound is not None:
            result['aps']['sound'] = self.sound
        if self.content_available:
            result['aps']['content-available'] = 1
        if self.mutable_content:
            result['aps']['mutable-content'] = 1
        if self.thread_id is not None:
            result['aps']['thread-id'] = self.thread_id
        if self.category is not None:
            result['aps']['category'] = self.category
        if self.url_args is not None:
            result['aps']['url-args'] = self.url_args
        if self.custom is not None:
            result.update(self.custom)

        return result

In the apns_async it is

request = NotificationRequest(
		device_token=registration_id,
		message={
			"aps": {
				"alert": alert,
				"badge": badge,
				"sound": sound,
				"thread-id": thread_id,
				**aps_kwargs,
			},
			**extra,
			**message_kwargs,
		},
		**notification_request_kwargs_out,
	)

Here alert, badge, sound, and thread_id got parameters and others are passed in **aps_kwargs.

mutable-content and category are added through my PRs. (#755 and #760).

content-available is getting added in this PR.

so, 2 more remaining:

  • url-args
  • custom

@HashimJVZ
Copy link
Contributor

@pomali , @50-Course
I think we can stick to bool and do

aps_kwargs = {}
if mutable_content:
	aps_kwargs["mutable-content"] = 1
if content_available:
	aps_kwargs["content-available"] = 1

Copy link
Member

@50-Course 50-Course left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update @pomali... looks like we ready to roll 👍🏼 🚀

@50-Course 50-Course merged commit cca865a into jazzband:master Feb 18, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apns_send_message() got an unexpected keyword argument 'content_available'
3 participants